package  
{
	import flash.events.IMEEvent;
	import net.flashpunk.graphics.TiledImage;
	import net.flashpunk.World;
	import net.flashpunk.FP;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.Sfx;
	
	/**
	 * ...
	 * @author Donatello
	 */
	public class GameWorld extends World
	{
		
		[Embed(source = "img/back.png" )] private const BACK:Class;
		private var back:Image = new Image(BACK);;	

		
		
		private var playerT:PlayerTank;
		private var playerB:Bomberman;
		private var ammoText:TextMessage;
		private var pressed:Boolean = false;
		
		public function GameWorld() 
		{
			addGraphic(back);
			
			agregarParedes();
			
			
			playerT= new PlayerTank(400, 400);
			add(playerT);
				
			ammoText = new TextMessage("Ammo " +playerT.ammo.toString(), 705, 20);
			
			playerB = new Bomberman(400, 400);
			add(playerB);
			
			add(ammoText);
			
		}
		
		override public function update():void
		{
			ammoText.changeText("Ammo " +playerT.ammo.toString());
			
			
			if (Input.check(Key.CONTROL))
			{
				if(!pressed)
				{
					if (playerT.bombMode)
					{
						if(playerT.collide("Bomberman",playerT.x,playerT.y))
						{
							playerT.bombMode = !playerT.bombMode;
							playerB.changeAlpha(playerT.bombMode);
							pressed = true;
						}
					}
					else
					{
						playerT.bombMode = !playerT.bombMode;
						playerB.changeAlpha(playerT.bombMode);
						playerB.x = playerT.x;
						playerB.y = playerT.y;
						pressed = true;	
					}
					
				}
			}
			else pressed = false;
			
			super.update();
		}
	
			
				
		public function agregarParedes():void
		{
			
			agregarBloque(150, 120);
			agregarBloque(150, 174);
			agregarBloque(150, 228);
			
			agregarBloque(350, 120);
			agregarBloque(350, 174);
			agregarBloque(350, 228);
			
			agregarBloque(550, 120);
			agregarBloque(550, 174);
			agregarBloque(550, 228);
			
		}
		
		public function agregarBloque(px:Number, py:Number):void
		{
			
			add(new Wall(px - 27, py - 27));
			add(new Wall(px, py - 27));
			add(new Wall(px - 27, py));
			add(new Wall(px, py));
		}
		
	}

}